import {mapGetters} from 'vuex';

export default {
    data() {
        return {
            filters: {
                mobile: '',
                area: '',
                position:''
            },
            smsLogTypeOptions: [
                {id: '智能功率变送器', name: '智能功率变送器'},
                {id: '温湿度氧气传感器', name: '温湿度氧气传感器'}
            ],
            iptIdOptions:[],
            thoIdOptions:[],
            addForm: {},
            addFormVisible: false,
            editForm: {},
            editFormVisible: false
        }
    },
    computed: {
        ...mapGetters([
            'smsLogList',
            'smsLogPage',
            'riskPositionList'
        ])
    },
    watch: {},
    components: {},
    mounted() {
        this.getAllDataOpt();
    },
    methods: {
        getAllDataOpt: function () {
            this.$store.dispatch('getSmsLogList', {...this.filters});
        },

        handleCurrentChange(val) {
            this.smsLogPage.page = val - 1;
            this.getAllDataOpt();
        },
        handleSizeChange(val) {
            this.smsLogPage.page = 0;
            this.smsLogPage.rows = val;
            this.getAllDataOpt();
        },
        handleSearch() {
            this.smsLogPage.page = 0;
            this.getAllDataOpt();
        },
        tableOperate(typeOpt, row) {
            if (typeOpt === 'edit') {
                this.editForm = Object.assign({}, row);
                this.editFormVisible = true;
            } else if (typeOpt === 'add') {
                this.addForm = {};
                this.addFormVisible = true;
            } else if (typeOpt === 'del') {
                this.$confirm('确认删除该记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.$store.dispatch('deletesmsLog', {id: row.id}).then((res) => {
                        this.getAllDataOpt();
                    });
                });
            }
        },
        addFormSubmit: function () {
            let requestData = Object.assign({}, this.addForm);
            this.$store.dispatch('addsmsLog', requestData).then((res) => {
                this.$message({
                    type: 'success',
                    message: '创建风险点成功'
                });
                this.getAllDataOpt();
                this.addFormVisible = false;
            });
        },
        editFormSubmit: function () {
            let requestData = Object.assign({}, this.editForm);
            this.$store.dispatch('editsmsLog', requestData).then((res) => {
                this.$message({
                    type: 'success',
                    message: '修改风险点成功'
                });
                this.getAllDataOpt();
                this.editFormVisible = false;
            });
        },
    }
}
